#include "feMvOps.h"
#include "feMatrix.h"
#include "feVector.h"
#include "feSmartPtr.h"


//-----------------------------------------------------------------------------------------------------------------------------------
bool feMvOps::AddLocalToGlobalV(feVector *ioG, feVector *iF, int *iFRemap, double iCoeff)
{
	//add
	for(int i=0; i<iF->GetSize(); i++)
		ioG->Data[iFRemap[i]] += iF->Data[i]*iCoeff;


	//done
	return true;
}


//-----------------------------------------------------------------------------------------------------------------------------------
bool feMvOps::PickLocalFromGlobalV(feVector *iG, feVector *oF, int *iIndeces)
{
	//pick
	for(int i=0; i<oF->GetSize(); i++)
		oF->Data[i] = iG->Data[iIndeces[i]];
	

	//done
	return true;
}


//-----------------------------------------------------------------------------------------------------------------------------------
void feMvOps::MultVAlpha(feVector *iV, double iAlpha, feVector *oV)
{
	for(int i=0; i<oV->GetSize(); i++)
		oV->Data[i] = iAlpha*iV->Data[i];
}


//-----------------------------------------------------------------------------------------------------------------------------------
void feMvOps::MultAddVV(feVector *iV1, feVector *iV2, feVector *oV, double iAlpha)
{
	for(int i=0; i<oV->GetSize(); i++)
		oV->Data[i] = iV1->Data[i] + iAlpha*iV2->Data[i];
}


//---------------------------------------------------------------------------------------------------------------------------------------
void feMvOps::MultSubVV(feVector *iFrom, feVector *iWhat, feVector *oRes, double iAlpha)
{
	MultAddVV(iFrom, iWhat, oRes, -iAlpha);
}


//-------------------------------------------------------------------------------------------------------------------------------
void feMvOps::CopyVV(feVector *iFrom, feVector *iTo)
{
	CopyMemory(&iTo->Data[0], &iFrom->Data[0], iTo->GetSize()*sizeof(feReal));
}


//--------------------------------------------------------------------------------------------------------------------------------
void feMvOps::DivideVV(feVector *iWhat, feVector *iTo, feVector *oRes)
{
	for(int i=0; i<oRes->GetSize(); i++)
		oRes->Data[i] = iWhat->Data[i]/iTo->Data[i];
}


//---------------------------------------------------------------------------------------------------------------------------
double feMvOps::DotVV(feVector *iV1, feVector *iV2) 
{
	double res = 0;
	for(int i=0; i<iV1->GetSize(); i++)
		res += iV1->Data[i] * iV2->Data[i];

	return res;
}